// koa-study/src/logger.ts
import { createLogger, format, transports } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';

const timezoned = () => {
  return new Date().toString();
};

const logger = createLogger({
  level: 'info',
  format: format.combine(
    format.timestamp({ format: timezoned }),
    format.json(),
  ),
  transports: [
    new transports.Console(),
    new DailyRotateFile({
      filename: 'logs/error-%DATE%.log',
      datePattern: 'YYYY-MM-DD',
      zippedArchive: true,
      maxSize: '2m',
      maxFiles: '1d',
      level: 'error'
    }),
    new DailyRotateFile({
      filename: 'logs/warn-%DATE%.log',
      datePattern: 'YYYY-MM-DD',
      zippedArchive: true,
      maxSize: '2m',
      maxFiles: '1d',
      level: 'warn'
    }),
    new DailyRotateFile({
      filename: 'logs/info-%DATE%.log',
      datePattern: 'YYYY-MM-DD',
      zippedArchive: true,
      maxSize: '2m',
      maxFiles: '1d',
      level: 'info'
    })
  ],
});

export default logger;